from tkinter import *
from lxg_tkinter import Quitter

fields = '姓名', '年龄', '职业'


def fetch(variables):
    for variable in variables:
        print("输入的变量：", variable.get())


def make_form(root, fields):
    # 创建外框
    form = Frame(root)
    # 创建两个列
    left = Frame(form)
    right = Frame(form)
    form.pack(fill=X)
    left.pack(side=LEFT)
    right.pack(side=RIGHT, expand=YES, fill=X)

    # 变量列表
    variables = []
    for field in fields:
        # 标签
        lab = Label(left, width=5, text=field)
        # 输入框
        ent = Entry(right)
        # 对齐
        lab.pack(side=TOP, fill=X)
        ent.pack(side=TOP, fill=X)
        # 变量
        var = StringVar()
        ent.config(textvariable=var)
        var.set("输入内容")
        variables.append(var)
    return variables


if __name__ == '__main__':
    root = Tk()
    vars = make_form(root, fields)
    Button(root, text='确认', command=(lambda: fetch(vars))).pack(side=LEFT)
    root.bind('<Return>', (lambda event: fetch(vars)))
    root.mainloop()
